#ifndef SINGLETON
#define SINGLETON

#include<string>

struct Singleton {
	static Singleton * init(std::string const & str = "") {
                if(counter < 1) {
			delete self;
                        counter = 1;
                        self = new Singleton(str);
		} else {
                    ++counter;
                }
		return self;
	}
	std::string toString() const;
        #ifndef USUAL_DELETE
        static void operator delete(void * addr) {
            ((Singleton *) addr)->deleteObj();
        }
        #endif
        ~Singleton();
private:
        Singleton(Singleton const & copy);
        void deleteObj();
	static Singleton * self;
	static int counter;
	explicit Singleton(std::string const & str);
	void swap(Singleton & right);
        char * str_;
        size_t size_;
};


#endif 
